<template>
    <div class="container">
        <div>
            <el-table class="el-table" align="center" :data="followinglist" stripe style="width: 80%">
                <el-table-column prop="focusDetails.acName" label="" width="100">
                </el-table-column>
                <!--            <el-table-column-->
                <!--                    prop="url"-->
                <!--                    label=""-->
                <!--                    width="100">-->
                <!--            </el-table-column>-->
                <el-table-column prop="focusDetails.personSignature" label="" width="100">
                </el-table-column>
                <el-table-column v-if="wo == bieren">
                    <template slot-scope="scope">
                        <el-button style="margin-left: 80%" type="danger" size="small"
                            @click="del(scope.row.followinglist.local_id)">取消关注</el-button>
                    </template>
                </el-table-column>

            </el-table>
        </div>
    </div>

</template>


<script>

import axios from "axios";

export default {
    data() {
        return {
            followinglist: [],
            wo: localStorage.getItem('userId'),
            bieren: localStorage.getItem('userpageId')

        }
    },
    created() {
        this.fetchFollows()
    },

    methods: {
        fetchFollows() {
            axios({
                url: "/api/focus/getLocal",
                method: 'post',
                headers: {
                    "HOSHINO_T_KK": localStorage.getItem("userToken"),
                },
            })
                .then(response => {
                    console.log(response.data);
                    this.followinglist = Array.isArray(response.data.data) ? response.data.data : [];
                })
                .catch(error => {
                    console.error('Error ', error);
                })
        },
        del() {
            this.$confirm('是否取消关注？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                axios({
                    url: "/api/focus/del",
                    method: 'post',
                    headers: {
                        "HOSHINO_T_KK": localStorage.getItem("userToken"),
                    },
                    data: {
                        local_id: this.local_id
                    }

                })
                    .then(response => {
                        console.log(response.data);
                        this.followinglist = Array.isArray(response.data.data) ? response.data.data : [];
                        this.fetchFollows();
                    })
                    .catch(error => {
                        console.error('Error ', error);
                    })

                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        }

    },




}
</script>

<style scoped>
.el-table {

    margin-left: 10%;
}

.container {
    margin-left: 10%;
    color: black;
    background-color: white;
    height: 100%;
    width: 70%;

}
</style>
